package com.rui.study.commons.model;

import lombok.Data;

@Data
public class Result<T> {

    private static final StatusCode DEFAULT_STATUS_CODE = StatusCode.SUCCEED;

    private String status;

    private String message;

    private T data;

    public Result() {
        this.status = DEFAULT_STATUS_CODE.getStatus();
        this.message = DEFAULT_STATUS_CODE.getMessage();
        this.data = null;
    }

    public Result(GlobalStatus globalStatus) {
        this.status = globalStatus.getStatus();
        this.message = globalStatus.getMessage();
    }

    public Result(GlobalStatus globalStatus, T data) {
        this.status = globalStatus.getStatus();
        this.message = globalStatus.getMessage();
        this.data = data;
    }

    public Result(String status, String message) {
        this.status = status;
        this.message = message;
        this.data = null;
    }

    public Result(String status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

     public boolean hasError() {
        return !DEFAULT_STATUS_CODE.getStatus().equals(this.status);
     }
}
